{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "77861a98-4ccd-4105-9ecb-7602b4ae603f",
   "metadata": {},
   "source": [
    "### 最大值最小值归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cf66cad6-540c-42b7-b6db-ab3744bbf882",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dd0c9d2d-b3da-4763-8f11-84fbc1939e63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.  ],\n",
       "       [0.25],\n",
       "       [0.5 ],\n",
       "       [1.  ],\n",
       "       [1.  ]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scaler = MinMaxScaler()\n",
    "temp = np.array([1,2,3,5,5])\n",
    "scaler.fit_transform(temp.reshape(-1,1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87827ac1-30d4-499d-9646-a9b42e806362",
   "metadata": {},
   "source": [
    "### 标准归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "51168727-2fbf-43d7-ae92-f965c14998bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6044dbd0-b6ad-44d6-83f4-d19e4a34727c",
   "metadata": {},
   "outputs": [],
   "source": [
    "scaler = StandardScaler()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b49f688c-b7d5-4116-b8b4-2463da81c3a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.375],\n",
       "       [-0.75 ],\n",
       "       [-0.125],\n",
       "       [ 1.125],\n",
       "       [ 1.125]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scaler.fit_transform(temp.reshape(-1,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "795df893-c3b3-4329-a380-94799d20d56d",
   "metadata": {},
   "outputs": [],
   "source": [
    "temp1 = np.array([1, 2, 3, 5, 50001])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cb9379e8-8132-461e-8f00-25e265526426",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.5000875 ],\n",
       "       [-0.5000375 ],\n",
       "       [-0.4999875 ],\n",
       "       [-0.49988749],\n",
       "       [ 2.        ]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scaler.fit_transform(temp1.reshape(-1,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33ada43a-7f51-4ea1-9033-bcd84d1cfce9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
